home *** CD-ROM | disk | FTP | other *** search
/ CD Exchange / CD Exchange - Volume 1.iso / d.t.p / utils / propage / donsgenies / donsgenies.lha / Don'sGenies / TextResize.pprx < prev    next >
Text File  |  1993-05-25  |  4KB  |  145 lines

  1. /* This Genie resizes text by a percentage factor, keeping the proportions of differing sizes of text in a box. All the text in a box or linked chain will be changed.
  2. Written by Don Cox. Not Public Domain. All rights reserved.  */
  3.  
  4. trace n
  5. signal on error
  6. signal on syntax
  7. address command
  8. call SafeEndEdit.rexx()
  9. call ppm_AutoUpdate(0)
  10. cr="0a"x
  11.  
  12. cpage = ppm_CurrentPage()
  13. counter=0
  14.  
  15. do forever
  16.     box=ppm_ClickOnBox("Click on boxes to be resized")
  17.     if box=0 then break
  18.     counter=counter+1
  19.     boxes.counter=box
  20.     call ppm_SelectBox(box)
  21. end
  22.  
  23. if counter=0 then exit_msg("No boxes selected")
  24.  
  25. percent = ppm_GetUserText(8,"Percentage of old size")
  26. if percent = "" then exit_msg("Aborted by User")
  27. if ~(datatype(percent,n)) then exit_msg("Invalid entry")
  28. factor = abs(percent/100)
  29. if factor>10 then factor = 10
  30. if factor<0.1 then factor = 0.1
  31.  
  32. currentunits=ppm_GetUnits()
  33. call ppm_SetUnits(2)
  34.  
  35. call ppm_ShowStatus("  Resizing text...")
  36. do i=1 to counter
  37.     box=boxes.i
  38.  
  39.     boxtype = upper(word(ppm_GetBoxInfo(box), 1))
  40.     if boxtype~="TEXT" then iterate
  41.     box = ppm_ArtFirstBox(box)
  42.     text = ppm_GetArticleText(box,1)
  43.     text = ResizeFonts(text,factor)
  44.     gone = ppm_DeleteContents(box)
  45.     overflow = ppm_TextIntoBox(box,text)
  46.  
  47.     end
  48.  
  49. newpage = ppm_GoToPage(cpage)
  50. call ppm_SetUnits(currentunits)
  51.  
  52. call exit_msg()
  53. end
  54.  
  55. /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
  56.  
  57. ResizeFonts: procedure
  58. parse arg text, factor
  59. position = 1
  60. position2 = 1
  61.  
  62. do forever  /* we have to open up style tags to get sizes */
  63.     position = pos("\dS<",text,position2)
  64.     if position = 0 then break
  65.     position2 = pos(">",text,position)
  66.     if position2 = 0 then break
  67.     styletag = substr(text,position+4, position2-position-4)
  68.     styledef = ppm_GetStyleTagData(styletag)
  69.     styledef = left(styledef,pos("}",styledef)-1) /* remove name of tag */
  70.     styledef = substr(styledef,pos("{",styledef)+1)
  71.     text = delstr(text,position, (position2-position+1)) /* delete tag name */
  72.     text = insert("\ds"styledef,text,(position-1))
  73.     end
  74.  
  75. position2 = 1
  76. do forever  /* first change font sizes */
  77.     position = pos("\fs<",text,position2)+4
  78.     if position = 4 then break  /* would be 0 but we added 4 */
  79.     position2 = pos(">",text,position)
  80.     if position2 = 0 then break
  81.     oldsize = substr(text,position, position2-position)
  82.     text = delstr(text,position, position2-position) /* delete old size */
  83.     newsize = oldsize*factor
  84.     if newsize>720 then newsize = 720
  85.     oddsize = newsize//0.125  /* round correctly to nearest 1/8 point - PPage always rounds down */
  86.     if oddsize>0.0625 then newsize = newsize-oddsize+0.125
  87.     else newsize = newsize-oddsize
  88.     text = insert(newsize,text,position-1)
  89.     end
  90.  
  91.  
  92. position2 = 1
  93. do forever  /*  now fixed line spacings  */
  94.     position = pos("\lf<",text,position2)+4
  95.     if position = 4 then break  /* would be 0 but we added 4 */
  96.     position2 = pos(">",text,position)
  97.     if position2 = 0 then break
  98.     oldsize = substr(text,position, position2-position)
  99.     text = delstr(text,position, position2-position) /* delete old size */
  100.     newsize = oldsize*factor
  101.     if newsize>720 then newsize = 720
  102.     oddsize = newsize//0.125  /* round correctly to nearest 1/8 point - PPage always rounds down */
  103.     if oddsize>0.0625 then newsize = newsize-oddsize+0.125
  104.     else newsize = newsize-oddsize
  105.     text = insert(newsize,text,position-1)
  106.     end
  107.  
  108. position2 = 1
  109. do forever   /* and fixed leading  */
  110.     position = pos("\ll<",text,position2)+4
  111.     if position = 4 then break  /* would be 0 but we added 4 */
  112.     position2 = pos(">",text,position)
  113.     if position2 = 0 then break
  114.     oldsize = substr(text,position, position2-position)
  115.     text = delstr(text,position, position2-position) /* delete old size */
  116.     newsize = oldsize*factor
  117.     if newsize>720 then newsize = 720
  118.     oddsize = newsize//0.125  /* round correctly to nearest 1/8 point - PPage always rounds down */
  119.     if oddsize>0.0625 then newsize = newsize-oddsize+0.125
  120.     else newsize = newsize-oddsize
  121.     text = insert(newsize,text,position-1)
  122.     end
  123.  
  124. return text
  125.  
  126.  
  127. /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
  128.  
  129. error:
  130. syntax:
  131.     do
  132.     exit_msg("Genie failed due to error: "errortext(rc))
  133.     end
  134.  
  135. exit_msg:
  136.     do
  137.     parse arg message
  138.     if message ~= "" then
  139.     call ppm_Inform(1,message,"Resume")
  140.     call ppm_ClearStatus()
  141.     call ppm_AutoUpdate(1)
  142.     exit
  143.     end
  144.  
  145.